#pragma once

#include <QWidget>

class MainFrame;
class SImageButton;
class AppMenu;
class TabBar;
class QPropertyAnimation;
class KeySearchWidget;
class StatusBar;

class TitleBar : public QWidget {
  Q_OBJECT
  Q_PROPERTY(int animateProgess READ progress WRITE setProgress)
 public:
  TitleBar(MainFrame* frame, QWidget* parent = nullptr);
  ~TitleBar();

  KeySearchWidget* searchWidget() const { return m_searchWidget; }
  StatusBar* statusBar() const { return m_statusBar; }

  void showSearch();

 public slots:
  void onCommonPage(int* ids, int size, int ntype);

 protected slots:
  void onBtnClicked();
  void onTabNeedResize(int type);
  void onSearchResultHide();
  void onAnimationFinished();
 signals:
  void setConfigAuth(int* ids, int size);
  void setCommonPage(int* ids, int size, int ntype);

 protected:
  void paintEvent(QPaintEvent* event) override;
  void mousePressEvent(QMouseEvent* event) override;
  void mouseReleaseEvent(QMouseEvent* event) override;
  void mouseDoubleClickEvent(QMouseEvent* event) override;
  void mouseMoveEvent(QMouseEvent* event) override;
  void resizeEvent(QResizeEvent* event) override;

 private:
  void maximizeMainFrame(bool max);
  int progress() const { return m_animateProgess; }
  void setProgress(int p);
  void startResizeAnimation(bool showSearch);

 private:
  MainFrame* m_frame = nullptr;
  AppMenu* m_menu = nullptr;
  KeySearchWidget* m_searchWidget = nullptr;
  TabBar* m_tabBar = nullptr;
  SImageButton* m_btnSearch = nullptr;
  QPoint m_lastMPos;
  bool m_canDrag = false;
  bool m_searchWidgetHide = false;
  QPropertyAnimation* m_animation = nullptr;
  int m_animateProgess = 0;
  SImageButton* m_btnMin = nullptr;
  SImageButton* m_btnFull = nullptr;
  SImageButton* m_btnClose = nullptr;
  SImageButton* m_btnRestore = nullptr;
  StatusBar* m_statusBar = nullptr;
};